package com.joymeter.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName Result
 * @Description TODO
 * 返回信息
 * @Author liang
 * @Date 2018/8/15 13:28
 * @Version 1.0
 **/
public class Result extends HashMap<String,Object> {
    private static final long serialVersionUID = 1L;
    public Result() {
        put("result", 0);
        put("msg", "success");
    }

    public static Result ok() {
        return new Result();
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.put("msg", msg);
        return r;
    }

    public static Result ok(Map<String, Object> map) {
        Result r = new Result();
        r.putAll(map);
        return r;
    }


    public static Result error(){
        return error(1,"后台服务未知异常");
    }

    public static Result error(String msg){
        return error(500,msg);
    }

    private static Result error(int result, String msg) {
        Result r = new Result();
        r.put("result", result);
        r.put("msg", msg);
        return r;
    }






    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
